import { defineStore } from "pinia";
import { ref } from "vue";

export const useUserStore = defineStore(
  "user",
  () => {
    let name = ref();
    let token = ref();
    const setName = (newName: any) => {
      name.value = newName;
    };
    const setToken = (newToken: any) => {
      token.value = newToken;
    };
    const clearDate = () => {
      name.value = undefined;
      token.value = undefined;
    };
    return {
      name,
      token,
      setName,
      setToken,
      clearDate,
    };
  },
  {
    persist: {
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value);
        },
        getItem(key) {
          return uni.getStorageSync(key);
        },
      },
    },
  }
);
